package com.margo.project.redis.message.configuration;

import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.data.redis.connection.RedisConnectionFactory;
import org.springframework.data.redis.listener.PatternTopic;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;
import org.springframework.data.redis.listener.adapter.MessageListenerAdapter;

/**
 * https://blog.csdn.net/u012326462/article/details/80515955  消息队列
 * @author fangxingbang
 * 
 * https://www.cnblogs.com/he-px/p/7593194.html   即发即弃
 *
 */
@Configuration
public class MargoMessageConfiguration {
	
	@Bean
	RedisMessageListenerContainer container(RedisConnectionFactory connectionFactory,
			MessageListenerAdapter messageListenerAdapter) {
		
		RedisMessageListenerContainer container = new RedisMessageListenerContainer();
		container.setConnectionFactory(connectionFactory);
		container.addMessageListener(messageListenerAdapter, new PatternTopic("FORECLOSURE_TOPIC"));
		return container;
	}
	
	@Bean
	public MessageListenerAdapter messageListenerAdapter(ReceiverRedisMessage receiverRedisMessage) {
		MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiverRedisMessage,
				"priceReceive");
		return messageListenerAdapter;
	
	}

}
